package com.songtao.rabbitmq.routing;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.songtao.rabbitmq.config.RabbitConfig;
import com.songtao.rabbitmq.util.RabbitConnectionUtils;

public class Send {
    
    
    public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
        
        Connection connection = RabbitConnectionUtils.getConnection();
        
        Channel channel = connection.createChannel();
        
      //保证只分发一次
        int prefetchCount = 1;
        channel.basicQos(prefetchCount);
        
        //声明路由
        channel.exchangeDeclare(RabbitConfig.EXCHANGE_SECOND, "direct");
        
        String msg = "hello rabbitmq direct info";
        channel.basicPublish(RabbitConfig.EXCHANGE_SECOND, "info", null, msg.getBytes());
        channel.close();
        connection.close();
    }
}
